const ok = require('../core/response-shortcut');

// const ValidatorNoteList = require('../validatorsFe/noteList');
 const PublicSquareListDao = require('../daoFe/publicSquareList.js');



class publicSquareListController {
  static async getPublicSquareList(ctx,hhh) {

    // 接收客户端参数
    let req = ctx.request.body;
    console.log('======吱吱吱ctx',ctx.query.v);
    //验证器,如果验证不通过,直接在验证器里报错
    //await ValidatorNoteList.insert(req)
    var [err, dbRes] = await PublicSquareListDao.getPublicSquareList(ctx);
    console.log('======吱吱吱ctx',dbRes);
    ctx.response.status = 200;
    if (err) {
      ctx.body = ok.fail(err)
    } else { 
      var obj = {
        list: dbRes,
        lastId:dbRes[dbRes.length-1].id
      }

      ctx.body = ok.json(obj)
    }
    
  }
}

module.exports = publicSquareListController